<?php
//员工
namespace app\crmindex\model;

use think\Db;

class Staff extends \ShopModel
{
    protected $table = 'sh_crm_staff';
    protected $pk = 'staff_id';
    protected $autoWriteTimestamp = true;
    protected $updateTime = false;
    protected $createTime = 'create_at';
    public function StaffDb(){
        return Db::name('crm_staff');
    }
    /**
     * 生成密码盐
     */
    public function generateSalt()
    {
        $str = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_';
        $strMaxIndex = strlen($str) - 1;
        $salt = '';
        $saltLenght = 6;
        for ($i = 0; $i < $saltLenght; $i ++) {
            $salt.= $str[mt_rand(0, $strMaxIndex)];
        }
        return $salt;
    }

    public function getCustodianTrans($status){
        $all_status = array(
            0 => '否',
            1 => '是',
        );
        return !empty($all_status[$status]) ? $all_status[$status] : '未知';
    }
    public function getLoginTrans($source){
        $all_status = array(
            0 => '不允许',
            1 => '允许',
         );
        return !empty($all_status[$source]) ? $all_status[$source] : '未知';
    }
   //查询用户详细信息
   public function getInfo($staff_id){
        $retData = Db::name('crm_staff')->where('staff_id',$staff_id)->field('staff_id,staff_sn,staff_name,staff_name,user_name,is_downstream,is_audit,is_dynamic_manage,is_dynamic')->find();
        return $retData;
   }
   //获取员工列表
    public function getYlist(){
       $data = Db::name('crm_staff')->where('is_downstream',1)->where('is_dynamic',0)->field('staff_id,staff_name')->select();
       return $data;
    }
   //获取下游列表
    public function getXlist(){
        $data = Db::name('crm_staff')->where('is_downstream',0)->where('is_dynamic',0)->field('staff_id,staff_name')->select();
        return $data;
    }

}
